/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.io.FileNotFoundException;
import java.sql.*;

/**
 *
 * @author RdX
 */
public class MySQLConn {

   public static void main(String args[]) throws SQLException {

      String query = "SELECT name FROM test";
      Connection connection = new MySQLConn().getConnection();
      PreparedStatement statement = connection.prepareStatement(query);
      ResultSet rs = statement.executeQuery();

      while (rs.next()) {
         System.out.println(rs.getString("name"));
      }
   }

   public static Connection getConnection() {
      Connection connection = null;
      try {
         Class.forName("com.mysql.jdbc.Driver");
         connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/nsep?" + "user=root&password=0000");
      } catch (SQLException sqe) {
        System.out.println("Cannot open connection");
      } catch (ClassNotFoundException e) {
         System.out.println("Class not found");
      }
      if (connection == null) {
         System.out.println("Error establishing connection!");
      }
      return connection;
   }
}
